import React, { PureComponent } from 'react'

function Intercept(Com) {
    return class extends PureComponent{
        state = {
            Template:null
        }
        render(){
            const {Template} = this.state
            return (
                Template
            )
        }
        componentDidMount(){
            let token = localStorage.getItem("token")
            if(token){
                this.setState({
                    Template:<Com {...this.props} />
                })
            }else{
                this.setState({
                    Template:null
                })
                this.props.history.push("/login")
            }
        }
    }
}

export default Intercept
